import httplib
from httplib import HTTP
from urlparse import urlparse
from google.appengine.ext.webapp import template
from s5code.s5code import S5Code
import os

class M:
	pathes = {
		'templates': '',
	}
	urls = {
		'base': ''
	}

	project_key = 'shortenedurls'
	
	@staticmethod
	def check_url(url):
		try:
			p = urlparse(url)
			h = HTTP(p[1])
			h.putrequest('HEAD', p[2])
			h.endheaders()
			return h.getreply()[0] == httplib.OK
		except:
			return False
	
	@staticmethod		
	def theme(template_file, values):
		path_to_template = '%s/%s.html' % (M.pathes['templates'], template_file)
		return template.render(path_to_template, values)
